
Page({

  data: {
    list:[],
    add:[],
    value:''
   
  },
  pack(){
    wx.removeStorageSync('name')
    this.setData({
      list:[],
      add:wx.getStorageSync('name')||[]
    })
  },
  toif(e){
    console.log(e.currentTarget.dataset.id);
    wx.navigateTo({
      url: '/pages/goodlist/goodlist?id='+e.currentTarget.dataset.id,
    })
  },
  onLoad(){
    this.setData({
      add:wx.getStorageSync('name')||[]
    })
  },
  toliba(e){
    console.log(e);
    this.setData({
      value:e.currentTarget.dataset.item
    })
    wx.request({
      url: 'https://www.uinav.com/api/public/v1/goods/qsearch',
      data:{
        query:e.currentTarget.dataset.item
      },
      success:res=>{
        console.log(res);
        this.setData({
          list:res.data.message
        })
        
      }
    })
  },
  onSearch(e){
  if(!e.detail){
    this.setData({
      list:[],
      add:[]
    })
    return
  }
  let add=wx.getStorageSync('name')||[]
  if(add.length>=10){
    add.pop()
  }
  add.push(e.detail)
  wx.setStorageSync('name',add)
  this.setData({
    add:wx.getStorageSync('name')||[]
  })

    wx.request({
      url: 'https://www.uinav.com/api/public/v1/goods/qsearch',
      data:{
        query:e.detail
      },
      success:res=>{
        console.log(res);
        this.setData({
          list:res.data.message
        })
        
      }
    })


  }

 
})